<?php
/**
 * M_quantification model 文件
 * @author  yxx
 * @date 2017-10-12
 */
class M_device extends MY_Model {

    public $table = 't_device';
    function __construct() {
        parent::__construct ();
    }
    	public function getDeptName($typeid){
		$sql = "SELECT d.department_name as deptname,d.department_id as deptid FROM t_department d INNER JOIN t_device_type t ON t.department_id = d.department_id where t.device_type_id={$typeid}";
		$ret = $this->db->query($sql)->row_array();
		return $ret;
	}
	//设备总条数
	public function getDeviceCount($where){
                          $sql="SELECT count(*) FROM(SELECT d.device_id,d.device_name,t.device_type_name,g.grid_name,m.department_name,d.xj_post_name,d.wx_post_name FROM t_device d LEFT JOIN t_device_type t on d.device_type_id=t.device_type_id LEFT JOIN t_grid g on g.grid_id=d.grid_id LEFT JOIN t_department m on m.department_id=t.department_id {$where}) aa";
                          $total   =  $this->query_count($sql);
		return $total;
	}
	//设备列表
	public function getDeviceList($where,$limit){
		$sql="SELECT * FROM t_device d LEFT JOIN t_device_type t on d.device_type_id=t.device_type_id LEFT JOIN t_grid g on g.grid_id=d.grid_id LEFT JOIN t_department m on m.department_id=t.department_id {$where} limit {$limit}";
		$data   =  $this->querylist($sql);
		return $data;
	}
	// 类型总条数
	public function getTypeCount($where){
                          $sql="SELECT count(*) FROM(SELECT t.device_type_id,t.device_type_name,m.department_name FROM t_device_type t LEFT JOIN t_department m ON t.department_id=m.department_id {$where}) aa";
                          $total   =  $this->query_count($sql);
		return $total;
	}
	// 类型列表
	public function getTypeList($where,$limit){
		$sql="SELECT t.device_type_id,t.device_type_name,m.department_name FROM t_device_type t LEFT JOIN t_department m ON t.department_id=m.department_id {$where} limit {$limit}";
		$data   =  $this->querylist($sql);
		return $data;
	}
	//报修记录总数
	public function getReportCount($where){
		$sql = "SELECT count(*) FROM(SELECT r.report_id,r.device_name,t.device_type_name,g.grid_name,p.post_name,u.user_name,m.department_name,r.report_addtime,r.report_status FROM t_device_report r LEFT JOIN t_device_type t ON t.device_type_id=r.device_type_id LEFT JOIN t_device d ON d.device_id=r.device_id LEFT JOIN t_grid g ON g.grid_id=d.grid_id LEFT JOIN t_user u ON u.user_id=r.report_user_id LEFT JOIN t_department m ON m.department_id=u.department_id LEFT JOIN t_post p ON p.post_id=d.wx_post_id {$where}) aa";
		$total   =  $this->query_count($sql);
		return $total;

	}
}